/**
 * @project lauwsys
 * @author Christian Teguh
 * @created 19 Okt 2011 04.19.08
 *
 */
package com.chimoz.lauwsys.business.repository.jdbc;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.chimoz.lauwsys.domain.Brand;
import com.chimoz.lauwsys.repository.BrandRepository;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/db/lauwsys-jdbc.xml"})
@TransactionConfiguration
@Transactional
public class JBrandRepositoryTestCase extends TestCase {

	@Autowired
	private BrandRepository brandRepository;
	
	@Test
	public void getBrandById() {
		Long id = new Long(2);
		Brand brand = this.brandRepository.getBrandById(id);
		assertNotNull(brand);
		assertEquals( brand.getId(), id );
        System.out.println(brand);
	}

	public void getAllBrands() {
		
		int off = 1;
		Integer limit = new Integer(10);
		Integer offset = limit * off;
		Map<String, String> criteria = new HashMap<String, String>();
		criteria.put("limit", limit.toString());
		criteria.put("offset", offset.toString());
		List<Brand> brands = this.brandRepository.listBrand(criteria);
		
		assertEquals( brands.size(), limit.intValue() );
	}
}
